package com.songshu.sca.nacosConfig;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;


/**
 * 使用前缀读取nacos配置。
 */
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "user")
@Slf4j
public class User implements InitializingBean, DisposableBean {

    private String name;

    private int age;

    private String address;

    private String name1;

    private List<String> hobbies;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getName1() {
        return name1;
    }

    public void setName1(String name1) {
        this.name1 = name1;
    }

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }


    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                ", name1='" + name1 + '\'' +
                ", hobbies=" + hobbies +
                '}';
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("[User Entity afterPropertiesSet()] " + toString());
    }

    @Override
    public void destroy() throws Exception {
        log.info("[User Entity destroy()] " + toString());
    }
}
